﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace WallNaming
{
	public class WallNamingManager
	{
		public WallNamingManager(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
			this.m_Doc = this.m_Revit.Application.ActiveUIDocument.Document;
		}

		public ExternalCommandData CmdData
		{
			get
			{
				return this.m_Revit;
			}
		}

		public Result Naming(ref string msg)
		{
			List<Wall> wallList = this.GetWallList();
			List<WallTypeInfo> wallTypeInfoList = this.ExtractWallTypeInfo(wallList);
			WallNamingManagementForm wallNamingManagementForm = new WallNamingManagementForm(this, wallTypeInfoList);
			if (wallNamingManagementForm.ShowDialog() != DialogResult.OK)
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public bool DeleteOneUselessType(WallTypeInfo wallTypeInfo)
		{
			if (wallTypeInfo.ElementsCount == 0)
			{
				if (!this.CanbeDeleteType(wallTypeInfo))
				{
					return false;
				}
				Transaction transaction = null;
				try
				{
					transaction = new Transaction(this.m_Doc);
					transaction.Start("delete type");
					wallTypeInfo.DeleteWallType(this.m_Revit.Application.ActiveUIDocument.Document);
					transaction.Commit();
					return true;
				}
				catch (Exception)
				{
					if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
					{
						transaction.RollBack();
					}
					return true;
				}
				return false;
			}
			return false;
		}

		public bool DeleteOneType(WallTypeInfo wallTypeInfo, ref List<WallTypeInfo> newWallTypeInfo)
		{
			if (!this.CanbeDeleteType(wallTypeInfo))
			{
				return false;
			}
			this.UpdateWallElements(wallTypeInfo, ref newWallTypeInfo);
			Transaction transaction = null;
			bool result;
			try
			{
				transaction = new Transaction(this.m_Doc);
				transaction.Start("delete type");
				wallTypeInfo.DeleteWallType(this.m_Revit.Application.ActiveUIDocument.Document);
				transaction.Commit();
				result = true;
			}
			catch (Exception)
			{
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				result = true;
			}
			return result;
		}

		public void DeleteAllUselessType(ref List<WallTypeInfo> wallTypeInfoList)
		{
			for (int i = 0; i < wallTypeInfoList.Count; i++)
			{
				WallTypeInfo wallTypeInfo = wallTypeInfoList[i];
				if (this.DeleteOneUselessType(wallTypeInfo))
				{
					wallTypeInfoList.RemoveAt(i);
					i--;
				}
			}
		}

		public List<StructLayersInfo> GetWallLayerInfoListByType(CompoundStructure compoundStructure)
		{
			List<StructLayersInfo> list = new List<StructLayersInfo>();
			int firstCoreLayerIndex = compoundStructure.GetFirstCoreLayerIndex();
			int lastCoreLayerIndex = compoundStructure.GetLastCoreLayerIndex();
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			for (int i = 0; i < layers.Count; i++)
			{
				if (-1 != firstCoreLayerIndex && firstCoreLayerIndex == i)
				{
					StructLayersInfo item = new StructLayersInfo(null, "核心边界", -1, "包络上层", "0.0");
					list.Add(item);
				}
				CompoundStructureLayer compoundStructureLayer = layers[i];
				string layerNameByMaterialFunction = this.GetLayerNameByMaterialFunction(compoundStructureLayer.Function);
				string materialName = this.GetMaterialName(compoundStructureLayer);
				string thickness = this.FeetToMM(compoundStructureLayer.Width).ToString();
				StructLayersInfo item2 = new StructLayersInfo(compoundStructureLayer, layerNameByMaterialFunction, compoundStructureLayer.LayerId, materialName, thickness);
				list.Add(item2);
				if (-1 != lastCoreLayerIndex && lastCoreLayerIndex == i)
				{
					StructLayersInfo item3 = new StructLayersInfo(null, "核心边界", -1, "包络下层", "0.0");
					list.Add(item3);
				}
			}
			return list;
		}

		public bool UpdateStructInfos(WallTypeInfo wallTypeInfo, List<StructLayersInfo> currentWallLayerInfo, ref string message)
		{
			Transaction transaction = new Transaction(this.m_Doc);
			bool result;
			try
			{
				transaction.Start("update struct info");
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_Doc);
				ICollection<Element> collection = filteredElementCollector.OfClass(typeof(Material)).ToElements();
				List<Material> list = new List<Material>();
				foreach (Element element in collection)
				{
					Material item = element as Material;
					list.Add(item);
				}
				IList<CompoundStructureLayer> list2 = new List<CompoundStructureLayer>();
				List<bool> list3 = new List<bool>();
				int i = 0;
				int num = -1;
				int num2 = -1;
				while (i < currentWallLayerInfo.Count)
				{
					StructLayersInfo layerInfo = currentWallLayerInfo[i];
					if (layerInfo.m_StructureLayer != null)
					{
						CompoundStructureLayer structureLayer = layerInfo.m_StructureLayer;
						int num3 = list.FindIndex((Material value) => value.Name.CompareTo(layerInfo.m_MaterialName) == 0);
						if (-1 != num3)
						{
							structureLayer.MaterialId = list[num3].Id;
						}
						else
						{
							structureLayer.MaterialId = ElementId.InvalidElementId;
						}
						structureLayer.Width = this.MMToFeet(Convert.ToDouble(layerInfo.m_Thickness));
						list2.Add(structureLayer);
                        if ((int)layerInfo.m_StructureLayer.Function == 1)
						{
							list3.Add(true);
						}
						else
						{
							list3.Add(false);
						}
					}
					else if (-1 == num)
					{
						num = i;
					}
					else
					{
						num2 = currentWallLayerInfo.Count - 1 - i;
					}
					i++;
				}
				CompoundStructure comStructure = wallTypeInfo.ComStructure;
				comStructure.SetLayers(list2);
                comStructure.SetNumberOfShellLayers((ShellLayerType)1, num);
                comStructure.SetNumberOfShellLayers((ShellLayerType)0, num2);
				for (i = 0; i < list3.Count; i++)
				{
					if (list3[i])
					{
						comStructure.StructuralMaterialIndex = i;
					}
					else
					{
						comStructure.SetParticipatesInWrapping(i, true);
					}
				}
				IDictionary<int, CompoundStructureError> dictionary;
				IDictionary<int, int> dictionary2;
                if (!comStructure.IsValid(this.m_Doc, out dictionary, out dictionary2))
				{
					if (dictionary.Count > 0)
					{
                        switch ((int)dictionary.First<KeyValuePair<int, CompoundStructureError>>().Value)
						{
						case 0:
							message = "层功能优先级不能从核心边界提高到面层面上";
							break;
						case 1:
							message = "核心层包含一个镀膜层或核心层厚度为零";
							break;
						case 3:
							message = "镀膜层厚度大于零";
							break;
						case 4:
							message = "非膜层厚度太薄";
							break;
						case 5:
							message = "外壳层层数大于总层数";
							break;
						case 6:
							message = "外层厚度太薄";
							break;
						case 7:
							message = "非膜层厚度为零";
							break;
						case 8:
							message = "层不能在核心边界的同一侧";
							break;
						case 9:
							message = "外层边界在某些高度有多于一个表面";
							break;
						case 10:
							message = "内核边界在某些高度有多于一个表面";
							break;
						case 11:
							message = "镀膜层在某些高度有多于一个表面";
							break;
						case 12:
							message = "顶部缺少结构层或者厚度太薄";
							break;
						case 13:
							message = "底部缺少结构层或者厚度太薄";
							break;
						case 14:
							message = "可变厚度层厚度为零";
							break;
						case 15:
							message = "元素的ID作为材料标识不符合实际的材质实体";
							break;
						case 16:
							message = "外延层上方的墙必须是相邻的";
							break;
						case 17:
							message = "外延层底部的墙必须是相邻的";
							break;
						case 18:
							message = "元素的ID作为轮廓标识不符合一个有效的结构剖面";
							break;
						}
					}
					if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
					{
						transaction.RollBack();
					}
					result = false;
				}
				else
				{
					wallTypeInfo.ComStructure = comStructure;
					transaction.Commit();
					result = true;
				}
			}
			catch (Exception)
			{
				message = "结构信息无效";
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				result = false;
			}
			return result;
		}

		public bool CopyCreateWallType(WallTypeInfo wallTypeInfo, List<NamingRegularInfo> namingRegularInfoList, List<Wall> wallInstanceList, bool isAdd, ref List<WallTypeInfo> newWallTypeInfoList)
		{
			Transaction transaction = new Transaction(this.m_Doc);
			transaction.Start("rename walltype");
			bool result;
			try
			{
				List<Level> levelsInfo = this.GetLevelsInfo(wallTypeInfo.WallTypeId, wallInstanceList);
				string newName = this.GetNewName(wallTypeInfo, namingRegularInfoList, wallInstanceList, levelsInfo);
				if (newName.CompareTo("") == 0)
				{
					MessageBox.Show("新命名为空", "盈建科提示");
					transaction.RollBack();
					result = false;
				}
				else if (newName.CompareTo(wallTypeInfo.FillName) == 0)
				{
					transaction.RollBack();
					result = false;
				}
				else
				{
					if (isAdd || levelsInfo.Count == 0)
					{
						WallType wallType = wallTypeInfo.Duplicate(newName);
						int num = 0;
						if (levelsInfo.Count == 0)
						{
							foreach (Wall wall in wallInstanceList)
							{
								if (wall.WallType.Id.IntegerValue == wallTypeInfo.WallTypeId.IntegerValue)
								{
									wall.WallType = wallType;
									num++;
								}
							}
						}
						WallTypeInfo item = new WallTypeInfo(wallType, newName, num);
						newWallTypeInfoList.Add(item);
					}
					else
					{
						if (this.IsSubType(wallTypeInfo) && levelsInfo.Count > 1)
						{
							transaction.RollBack();
							return false;
						}
						if (levelsInfo.Count == 1)
						{
							string text = newName;
							text = text.Replace("$$$$", levelsInfo[0].Name);
							wallTypeInfo.SetWallTypeName(text);
							wallTypeInfo.FillName = text;
							newWallTypeInfoList.Add(wallTypeInfo);
						}
						else
						{
							if (newName.IndexOf("$$$$") != -1)
							{
								using (List<Level>.Enumerator enumerator2 = levelsInfo.GetEnumerator())
								{
									while (enumerator2.MoveNext())
									{
										Level level = enumerator2.Current;
										string text2 = newName;
										text2 = text2.Replace("$$$$", level.Name);
										this.CopyNewType(wallTypeInfo, text2, wallInstanceList, level, ref newWallTypeInfoList);
									}
									goto IL_1DE;
								}
							}
							this.CopyNewType(wallTypeInfo, newName, wallInstanceList, null, ref newWallTypeInfoList);
						}
					}
					IL_1DE:
					transaction.Commit();
					result = true;
				}
			}
			catch (Exception)
			{
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				result = false;
			}
			return result;
		}

		private void CopyNewType(WallTypeInfo wallTypeInfo, string currentNewName, List<Wall> wallInstanceList, Level levelInfo, ref List<WallTypeInfo> newWallTypeInfoList)
		{
			WallType wallType = wallTypeInfo.Duplicate(currentNewName);
			int num = 0;
			foreach (Wall wall in wallInstanceList)
			{
				if (wall.WallType.Id.IntegerValue == wallTypeInfo.WallTypeId.IntegerValue)
				{
					ElementId elementId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
					Level level = this.m_Doc.GetElement(elementId) as Level;
					if (levelInfo == null || level.Id.IntegerValue == levelInfo.Id.IntegerValue)
					{
						wall.WallType = wallType;
						num++;
					}
				}
			}
			WallTypeInfo item = new WallTypeInfo(wallType, currentNewName, num);
			newWallTypeInfoList.Add(item);
		}

		private string GetNewName(WallTypeInfo wallTypeInfo, List<NamingRegularInfo> namingRegularInfoList, List<Wall> wallInstanceList, List<Level> levelsInfo)
		{
			CompoundStructureLayer compoundStructureLayer = null;
			string subString = "";
			string subString2 = "";
			if (wallTypeInfo.TheWallKind == null)
			{
				compoundStructureLayer = this.GetWallStructLayerInfo(wallTypeInfo.ComStructure);
				this.GetWallFinishLayerInfo(wallTypeInfo.ComStructure, ref subString, ref subString2);
			}
			string text = "";
			foreach (NamingRegularInfo namingRegularInfo in namingRegularInfoList)
			{
				if (namingRegularInfo.m_Checked)
				{
					switch (namingRegularInfo.m_Type)
					{
					case NamingRegularType.NRT_Categoty:
						text = this.AddSubString(text, namingRegularInfo.m_RegularValue);
						break;
					case NamingRegularType.NRT_Region:
						if (namingRegularInfo.m_RegularValue.CompareTo("") != 0)
						{
							text = this.AddSubString(text, namingRegularInfo.m_RegularValue);
						}
						break;
					case NamingRegularType.NRT_Level:
						if (levelsInfo.Count > 0)
						{
							text = this.AddSubString(text, "$$$$");
						}
						break;
					case NamingRegularType.NRT_Struct:
						if (wallTypeInfo.TheWallKind == null)
						{
							text = this.AddSubString(text, this.GetMaterialName(compoundStructureLayer));
						}
						break;
					case NamingRegularType.NRT_StructThickness:
						if (wallTypeInfo.TheWallKind == null)
						{
							string subString3 = "0.0";
							if (compoundStructureLayer != null)
							{
								subString3 = this.FeetToMM(compoundStructureLayer.Width).ToString();
							}
							text = this.AddSubString(text, subString3);
						}
						break;
					case NamingRegularType.NRT_Finish:
						if (namingRegularInfo.m_AutoName)
						{
							if (wallTypeInfo.TheWallKind == null)
							{
								text = this.AddSubString(text, subString);
							}
						}
						else
						{
							text = this.AddSubString(text, namingRegularInfo.m_RegularValue);
						}
						break;
					case NamingRegularType.NRT_FinishThickness:
						if (namingRegularInfo.m_AutoName)
						{
							if (wallTypeInfo.TheWallKind == null)
							{
								text = this.AddSubString(text, subString2);
							}
						}
						else
						{
							text = this.AddSubString(text, namingRegularInfo.m_RegularValue);
						}
						break;
					case NamingRegularType.NRT_Suffix:
						if (namingRegularInfo.m_RegularValue.CompareTo("") != 0)
						{
							text = this.AddSubString(text, namingRegularInfo.m_RegularValue);
						}
						break;
					}
				}
			}
			text += this.GetSuffix(wallTypeInfo.FillName);
			text = this.GetNewName(text);
			return text;
		}

		private string AddSubString(string oldString, string subString)
		{
			if (oldString.CompareTo("") == 0)
			{
				return subString;
			}
			if (subString.CompareTo("") == 0)
			{
				return oldString;
			}
			return oldString = oldString + "_" + subString;
		}

		private string GetSuffix(string oldName)
		{
			string result = "";
			List<string> list = SuffixMarkSettingForm.ReadSuffixMarkList();
			foreach (string value in list)
			{
				int num = oldName.LastIndexOf(value);
				if (num != -1)
				{
					result = oldName.Substring(num, oldName.Length - num);
					break;
				}
			}
			return result;
		}

		public CompoundStructureLayer GetWallStructLayerInfo(CompoundStructure compoundStructure)
		{
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			foreach (CompoundStructureLayer compoundStructureLayer in layers)
			{
                if ((int)compoundStructureLayer.Function == 1)
				{
					return compoundStructureLayer;
				}
			}
			return null;
		}

		public List<Level> GetLevelsInfo(ElementId wallTypeId, List<Wall> wallInstanceList)
		{
			List<Level> list = new List<Level>();
			foreach (Wall wall in wallInstanceList)
			{
				if (wall.WallType.Id.IntegerValue == wallTypeId.IntegerValue)
				{
					ElementId elementId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
					Level level = this.m_Doc.GetElement(elementId) as Level;
					int num = list.FindIndex((Level value) => value.Id.IntegerValue == level.Id.IntegerValue);
					if (num == -1)
					{
						list.Add(level);
					}
				}
			}
			list.Sort(new LevelComparer());
			return list;
		}

		public void GetWallFinishLayerInfo(CompoundStructure compoundStructure, ref string finishValue, ref string finishThicknessValue)
		{
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			int num = 0;
			foreach (CompoundStructureLayer compoundStructureLayer in layers)
			{
                if ((int)compoundStructureLayer.Function == 4 || (int)compoundStructureLayer.Function == 5)
				{
					string materialName = this.GetMaterialName(compoundStructureLayer);
					string text = this.FeetToMM(compoundStructureLayer.Width).ToString();
					if (num == 0)
					{
						finishValue = materialName;
						finishThicknessValue = text;
					}
					else
					{
						finishValue = finishValue + "_" + materialName;
						finishThicknessValue = finishThicknessValue + "_" + text;
					}
					num++;
				}
			}
		}

		public string GetLayerNameByMaterialFunction(MaterialFunctionAssignment function)
		{
			string result = "";
            switch ((int)function)
			{
			case 1:
				result = "结构";
				break;
			case 2:
				result = "衬底";
				break;
			case 3:
				result = "保温层/空气层";
				break;
			case 4:
				result = "面层1";
				break;
			case 5:
				result = "面层2";
				break;
			default:
                if ((int)function != 100)
				{
                    if ((int)function == 200)
					{
						result = "结构装饰";
					}
				}
				else
				{
					result = "涂膜层";
				}
				break;
			}
			return result;
		}

		public string GetMaterialName(CompoundStructureLayer layer)
		{
			if (layer == null)
			{
				return "无";
			}
			ElementId materialId = layer.MaterialId;
			if (materialId == ElementId.InvalidElementId || null == materialId)
			{
				return "按类别";
			}
			Element element = this.m_Revit.Application.ActiveUIDocument.Document.GetElement(materialId);
			Material material = element as Material;
			return material.Name;
		}

		private bool CanbeDeleteType(WallTypeInfo wallTypeInfo)
		{
			Document document = this.m_Revit.Application.ActiveUIDocument.Document;
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
			ICollection<Element> collection = filteredElementCollector.OfClass(typeof(WallType)).ToElements();
			int num = 1;
			foreach (Element element in collection)
			{
				WallType wallType = element as WallType;
				if (wallType.Id.IntegerValue != wallTypeInfo.WallTypeId.IntegerValue && wallType.Kind == wallTypeInfo.TheWallKind)
				{
					num++;
				}
			}
			if (num < 2)
			{
				return false;
			}
            if ((int)wallTypeInfo.TheWallKind != 2)
			{
				int num2 = wallTypeInfo.WallTypeName.IndexOf("复合墙");
				if (num2 != -1)
				{
					return false;
				}
			}
			return true;
		}

		private bool IsSubType(WallTypeInfo wallTypeInfo)
		{
            if ((int)wallTypeInfo.TheWallKind != 2)
			{
				int num = wallTypeInfo.WallTypeName.IndexOf("复合墙");
				if (num == -1)
				{
					return false;
				}
			}
			return true;
		}

		private void UpdateWallElements(WallTypeInfo wallTypeInfo, ref List<WallTypeInfo> newWallTypeInfo)
		{
			Transaction transaction = new Transaction(this.m_Doc);
			transaction.Start("UpdateWallElements");
			try
			{
				Document document = this.m_Revit.Application.ActiveUIDocument.Document;
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
				ICollection<Element> collection = filteredElementCollector.OfClass(typeof(Wall)).ToElements();
				foreach (Element element in collection)
				{
					Wall wall = element as Wall;
					if (wall.WallType.Id.IntegerValue == wallTypeInfo.WallTypeId.IntegerValue)
					{
						if (wallTypeInfo.IsChanged)
						{
							int num = newWallTypeInfo.FindIndex((WallTypeInfo value) => value.WallTypeId.IntegerValue == wallTypeInfo.WallTypeId.IntegerValue);
							if (num != -1)
							{
								newWallTypeInfo[num].SetWallType(ref wall);
							}
						}
						else
						{
							ElementId elementId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
							string levelName = this.m_Doc.GetElement(elementId).Name;
							int num2 = newWallTypeInfo.FindIndex((WallTypeInfo value) => value.FillName.IndexOf(levelName) != -1);
							if (num2 != -1)
							{
								newWallTypeInfo[num2].SetWallType(ref wall);
								int elementsCount = newWallTypeInfo[num2].ElementsCount + 1;
								newWallTypeInfo[num2].ElementsCount = elementsCount;
							}
						}
					}
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
			}
		}

		public List<Wall> GetWallList()
		{
			List<Wall> list = new List<Wall>();
			Document document = this.m_Revit.Application.ActiveUIDocument.Document;
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
			ICollection<Element> collection = filteredElementCollector.OfClass(typeof(Wall)).ToElements();
			foreach (Element element in collection)
			{
				Wall item = element as Wall;
				list.Add(item);
			}
			return list;
		}

		private List<WallType> GetWallTypeList()
		{
			List<WallType> list = new List<WallType>();
			Document document = this.m_Revit.Application.ActiveUIDocument.Document;
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
			ICollection<Element> collection = filteredElementCollector.OfClass(typeof(WallType)).ToElements();
			foreach (Element element in collection)
			{
				WallType item = element as WallType;
				list.Add(item);
			}
			return list;
		}

		private string GetNewName(string newName)
		{
            //WallNamingManager.<>c__DisplayClass10 <>c__DisplayClass = new WallNamingManager.<>c__DisplayClass10();
            //List<string> list = new List<string>();
            //Document document = this.m_Revit.Application.ActiveUIDocument.Document;
            //FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
            //ICollection<Element> collection = filteredElementCollector.OfClass(typeof(WallType)).ToElements();
            //foreach (Element element in collection)
            //{
            //    WallType wallType = element as WallType;
            //    list.Add(wallType.Name);
            //}
            //<>c__DisplayClass.res = "";
            //int num = 0;
            //for (;;)
            //{
            //    <>c__DisplayClass.res = newName;
            //    if (num != 0)
            //    {
            //        WallNamingManager.<>c__DisplayClass10 <>c__DisplayClass2 = <>c__DisplayClass;
            //        <>c__DisplayClass2.res = <>c__DisplayClass2.res + "(" + num.ToString() + ")";
            //    }
            //    int num2 = list.FindIndex((string value) => value.CompareTo(<>c__DisplayClass.res) == 0);
            //    if (num2 == -1)
            //    {
            //        break;
            //    }
            //    num++;
            //}
            //return <>c__DisplayClass.res;
            return "";
		}

		private List<WallTypeInfo> ExtractWallTypeInfo(List<Wall> wallList)
		{
			List<WallTypeInfo> list = new List<WallTypeInfo>();
			using (List<Wall>.Enumerator enumerator = wallList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Wall wall = enumerator.Current;
					int num = list.FindIndex((WallTypeInfo value) => value.WallTypeId.IntegerValue == wall.WallType.Id.IntegerValue);
					if (-1 == num)
					{
						WallTypeInfo item = new WallTypeInfo(wall.WallType, wall.WallType.Name, 1);
						list.Add(item);
					}
					else
					{
						list[num] = new WallTypeInfo(wall.WallType, wall.WallType.Name, list[num].ElementsCount + 1);
					}
				}
			}
			List<WallType> wallTypeList = this.GetWallTypeList();
			using (List<WallType>.Enumerator enumerator2 = wallTypeList.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					WallType wallType = enumerator2.Current;
					int num2 = list.FindIndex((WallTypeInfo value) => value.WallTypeId.IntegerValue == wallType.Id.IntegerValue);
					if (-1 == num2)
					{
						WallTypeInfo item2 = new WallTypeInfo(wallType, wallType.Name, 0);
						list.Add(item2);
					}
				}
			}
			list.Sort(new WallTypeInfoComparer());
			return list;
		}

		private double MMToFeet(double val)
		{
			return val / 304.8;
		}

		private double FeetToMM(double val)
		{
			return val * 304.8;
		}

		private ExternalCommandData m_Revit;

		private Document m_Doc;
	}
}
